<template>
    <div class="app-container tz-app">


        <div class="zt-select flex-s">
            <div class="flex-left">
                <el-select v-model="queryParams.radioStationName" filterable placeholder="电台名称" class="zt-input rihgt-m5">
                    <el-option v-for="item in options" :key="item.label" :label="item.label" :value="item.label">
                    </el-option>
                </el-select>
                <button class="bt-blue " @click="handleQuery">筛选</button>

            </div>
            <button class="bt-yellow " @click="handleAdd">新增</button>
            <!-- <el-input v-model="queryParams.antennaName" placeholder="请输入天线名称" class="zt-input" clearable
        @keyup.enter.native="handleQuery" /> -->

        </div>

        <div class="tz-table-box" style="height:calc(100vh - 250px);">
            <el-table v-loading="loading" :data="stationList" @selection-change="handleSelectionChange"
                height="calc(100vh - 250px)" class="zt-table" :empty-text="'暂无数据'">
                <!-- <el-table-column label="电台ID" align="center" prop="radioStationId" /> -->
                <el-table-column label="电台名称" align="center" prop="radioStationName" width="150" />
                <el-table-column label="电台类型" align="center" prop="radioStationType" />
                <el-table-column label="软件版本号" align="center" prop="softwareVersion" width="90" />
                <el-table-column label="硬件版本号" align="center" prop="hardwareVersion" width="90" />
                <el-table-column label="电台GPS" align="center" prop="radioStationGps" width="180" />
                <el-table-column label="搭载类型" align="center" prop="carryType" />
                <!-- <el-table-column label="电台编码" align="center" prop="radioStationCode" /> -->
                <el-table-column label="所属单位" align="center" prop="unit" />
                <el-table-column label="地址" align="center" prop="address" />
                <el-table-column label="天线ID" align="center" prop="antennaId" />
                <el-table-column label="状态" align="center" prop="isNet" />
                <el-table-column label="状态" align="center" prop="status" />
                <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
                    <template slot-scope="scope">
                        <img src="@/assets/images/amend.png"
                            style="width: 20px;height: 20px;cursor: pointer;margin-right: 10px;"
                            @click="handleUpdate(scope.row)" />
                        <img src="@/assets/images/delete-bin2.png"
                            style="width: 20px;height: 20px;cursor: pointer;margin-right: 10px;"
                            @click="handleDelete(scope.row)" />
                        <img src="@/assets/images/xs.png" @click="handleDetails(scope.row)"
                            style="width: 20px;height: 20px;cursor: pointer;margin-right: 10px;" />
                        <img src="@/assets/images/st.png" style="width: 20px;height: 20px;cursor: pointer;" />
                    </template>
                </el-table-column>
            </el-table>

        </div>



        <div class="zt-pagination">
            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList" />
        </div>

        <right-dialog :title="title" :visible="open" @closeDialog="cancel">
            <template v-slot:default>
                <div class="zt-dialog-solt">
                    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
                        <el-form-item label="类型:">
                            <div class="flex">
                                <el-select v-model="form.radioStationType" filterable placeholder="类型" @change="changeType"
                                    class="zt-input-min rihgt-m5" style="width: 120px;font-weight: 600;">
                                    <el-option v-for="item in  dict.type.radio_station_type" :key="item.value"
                                        :label="item.label" :value="item.value" />
                                </el-select>
                                <!-- <div style=";margin-right: 5px; width: 90px; text-align: right;">所属地:</div> -->
                                <el-form-item label="所属地:" prop="locatedAddress">
                                    <el-select v-model="form.locatedAddress" filterable placeholder="所属地"
                                        @change="changeLocatedAddress" class="zt-input-min rihgt-m5"
                                        style="width: 120px;font-weight: 600;">
                                        <el-option v-for="item in  dict.type.located_address" :key="item.value"
                                            :label="item.label" :value="item.value" />
                                    </el-select>
                                </el-form-item>

                                <el-form-item label="天线:" v-show="form.locatedAddress">

                                    <el-select v-model="form.antennaId" filterable placeholder="天线"
                                        class="zt-input-min rihgt-m5" style="width: 120px;font-weight: 600;">
                                        <el-option v-for="item in  antennaListAll" :key="item.antennaId"
                                            :label="item.antennaName" :value="item.antennaId" />
                                    </el-select>
                                </el-form-item>


                            </div>
                        </el-form-item>

                        <el-form-item label="硬件版本号:">
                            <div class="flex">
                                <el-input class="zt-input-min" style="width: 120px;" v-model="form.hardwareVersion"
                                    placeholder="版本号" />
                                <div
                                    style="margin-right: 5px; width: 80px; text-align: right;font-weight: 600;margin-left: 30px;">
                                    软件版本号:
                                </div>
                                <el-input class="zt-input-min" style="width: 120px;" v-model="form.softwareVersion"
                                    placeholder="版本号" />

                                <div style=";margin-right: 5px; width: 90px; text-align: right;">入网状态:
                                </div>
                                <el-select v-model="form.isNet" filterable placeholder="入网状态" :disabled="isNet == 1"
                                    class="zt-input-min rihgt-m5">
                                    <el-option key="0" label="未入网" value="0" />
                                    <el-option key="1" label="已入网" value="1" />
                                </el-select>
                            </div>

                        </el-form-item>

                        <el-form-item label="电台名称:">
                            <div class="flex">
                                <div
                                    style="width: 100%;background-color: #2CA6E0;color: white;border-radius: 50px;padding-left:10px ;height: 35px;">
                                    {{ form.radioStationName }}</div>
                                <el-button class="bt-blue " @click="submitForm" style="margin-left: 50px; ">确定</el-button>
                            </div>
                        </el-form-item>
                        <el-form-item label="备注:" prop="remark">
                            <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
                        </el-form-item>
                    </el-form>

                </div>
            </template>
        </right-dialog>



        <right-dialog :title="title" :visible="openDetails" @closeDialog="cancel">
            <template v-slot:default>
                <div class="zt-dialog-solt-2">
                    <div class="flex station-head-box">
                        <div class="station-head1">重庆万洲对周螺旋F006</div>
                        <div class="station-head2"><img src="@/assets/images/antenna-icon.png" /></div>
                        <div class="station-head3">
                            <div class="sh-box flex-s">
                                <div class="sh-1">旋转周螺旋F006旋转周螺旋F006</div>
                                <div class="sh-2">|</div>
                                <div class="sh-3">发射中</div>
                                <img class="sh-4" src="@/assets/images/js.png" />
                            </div>
                        </div>
                        <div class="station-head4 flex-s">
                            <img src="@/assets/images/amend.png">
                            <img src="@/assets/images/delete-bin2.png">
                            <img src="@/assets/images/qqq.png">
                            <img src="@/assets/images/st.png">
                        </div>
                    </div>

                    <div class="bg-black">状态信息</div>

                    <div class="flex station-information">
                        <div class="information-left">
                            <div class="flex information-ul">
                                <div class="information-li"><img src="@/assets/images/station2.png" /><span
                                        class="li-text">状态:空闲</span></div>
                                <div class="information-li"><img src="@/assets/images/station3.png" /><span
                                        class="li-text">驻波:0.3</span></div>
                                <div class="information-li"><img src="@/assets/images/station6.png" /><span
                                        class="li-text">电压:2.2V</span></div>
                            </div>
                            <div class="flex information-ul">
                                <div class="information-li "><img src="@/assets/images/station2.png" /><span
                                        class="li-text">温度:32℃</span></div>
                                <div class="information-li "><img src="@/assets/images/station3.png" /><span
                                        class="li-text">电流:2.3A</span></div>
                                <div class="information-li "><img src="@/assets/images/station6.png" /><span
                                        class="li-text">功率:8高</span></div>
                            </div>
                            <div class="flex information-ul">
                                <div class="information-li"><img src="@/assets/images/station2.png" /><span
                                        class="li-text">频率:2.1MHz</span></div>

                            </div>
                        </div>
                        <div class="information-right">
                            <div class="flex information-ul">
                                <div class="information-li"><img src="@/assets/images/station2.png" /><span
                                        class="li-text">软件版本:1</span></div>
                                <div class="information-li"><span class="li-text">软件版本:2</span></div>

                            </div>
                            <div class="flex information-ul">
                                <div class="information-li "><img src="@/assets/images/station2.png" /><span
                                        class="li-text">温度:32℃温度:32℃温度:32℃温度:32℃温度:32℃温度:32℃</span></div>
                            </div>


                        </div>

                    </div>

                    <div class="bg-blue flex-s">
                        <div>当前执行任务:重庆万州电台连续测试</div>
                    </div>

                    <div class="bg-black">发送信息</div>

                    <div class="send-box">
                        <div class="send-1"></div>
                        <div class="send-2"></div>
                    </div>

                    <div class="bg-black">频率图</div>
                </div>
            </template>
        </right-dialog>


        <!-- 添加或修改电台对话框 -->
        <!-- <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                <el-form-item label="电台名称" prop="radioStationName">
                    <el-input v-model="form.radioStationName" placeholder="请输入电台名称" />
                </el-form-item>
                <el-form-item label="电台编码" prop="radioStationCode">
                    <el-input v-model="form.radioStationCode" placeholder="请输入电台编码" />
                </el-form-item>
                <el-form-item label="所属单位" prop="unit">
                    <el-input v-model="form.unit" placeholder="请输入所属单位" />
                </el-form-item>
                <el-form-item label="地址" prop="address">
                    <el-input v-model="form.address" placeholder="请输入地址" />
                </el-form-item>
                <el-form-item label="天线ID" prop="antennaId">
                    <el-input v-model="form.antennaId" placeholder="请输入天线ID" />
                </el-form-item>
                <el-form-item label="软件版本号" prop="softwareVersion">
                    <el-input v-model="form.softwareVersion" placeholder="请输入软件版本号" />
                </el-form-item>
                <el-form-item label="硬件版本号" prop="hardwareVersion">
                    <el-input v-model="form.hardwareVersion" placeholder="请输入硬件版本号" />
                </el-form-item>
                <el-form-item label="状态" prop="isNet">
                    <el-input v-model="form.isNet" placeholder="请输入状态" />
                </el-form-item>
                <el-form-item label="备注" prop="remark">
                    <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog> -->
    </div>
</template>
  
<script>
import { listStation, getStation, delStation, addStation, updateStation } from "@/api/business/station";
import { getAntennaListAll } from "@/api/business/antenna";
import RightDialog from "@/components/TZ/RightDialog"

export default {
    components: { RightDialog },
    dicts: ['radio_station_type', 'located_address'],
    name: "Station",
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 电台表格数据
            stationList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            openDetails: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 20,
                radioStationName: null,
                radioStationType: null,
                carryType: null,
                radioStationCode: null,
                unit: null,
                address: null,
                antennaId: null,
                softwareVersion: null,
                hardwareVersion: null,
                radioStationGps: null,
                isNet: null,
                status: null,
            },
            //天线集合
            antennaListAll: [],
            // 表单参数
            form: {},
            // 表单校验
            rules: {
                radioStationName: [
                    { required: true, message: "电台名称不能为空", trigger: "blur" }
                ],
                radioStationType: [
                    { required: true, message: "电台类型不能为空", trigger: "change" }
                ],
                carryType: [
                    { required: true, message: "搭载类型不能为空", trigger: "change" }
                ],
                radioStationCode: [
                    { required: true, message: "电台编码不能为空", trigger: "blur" }
                ],
                unit: [
                    { required: true, message: "所属单位不能为空", trigger: "blur" }
                ],
                address: [
                    { required: true, message: "地址不能为空", trigger: "blur" }
                ],
                softwareVersion: [
                    { required: true, message: "软件版本号不能为空", trigger: "blur" }
                ],
                hardwareVersion: [
                    { required: true, message: "硬件版本号不能为空", trigger: "blur" }
                ],
                radioStationGps: [
                    { required: true, message: "电台GPS不能为空", trigger: "blur" }
                ],
                isNet: [
                    { required: true, message: "状态不能为空", trigger: "blur" }
                ],
                status: [
                    { required: true, message: "状态不能为空", trigger: "change" }
                ],
            },
            isNet: 0,
            options: [{
                value: '1',
                label: '1'
            }, {
                value: '天线',
                label: '天线'
            }, {
                value: '2',
                label: '2'
            }, {
                value: '3',
                label: '3'
            }, {
                value: '天下七七',
                label: '天下七七'
            }],
        };
    },
    created() {
        this.getList();
    },
    methods: {
        /** 查询电台列表 */
        getList() {
            this.loading = true;
            listStation(this.queryParams).then(response => {
                this.stationList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.openDetails = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                radioStationId: null,
                radioStationName: null,
                radioStationType: null,
                carryType: null,
                radioStationCode: null,
                locatedAddress: null,
                unit: null,
                address: null,
                antennaId: null,
                softwareVersion: null,
                hardwareVersion: null,
                radioStationGps: null,
                isUsed: null,
                isNet: null,
                status: null,
                createBy: null,
                createTime: null,
                updateBy: null,
                updateTime: null,
                remark: null
            };
            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.radioStationId)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.open = true;
            this.title = "添加电台";
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset();
            const radioStationId = row.radioStationId || this.ids
            getStation(radioStationId).then(response => {
                this.form = response.data;
                this.open = true;
                this.isNet = this.form.isNet;
                this.title = "修改电台";
                if (this.form.locatedAddress) {
                    getAntennaListAll(this.form.locatedAddress).then(res => {
                        this.antennaListAll = res.rows;
                    });
                }

            });
        },
        handleDetails(row) {
            this.reset();
            const radioStationId = row.radioStationId || this.ids
            getStation(radioStationId).then(response => {
                this.form = response.data;
                this.openDetails = true;
                this.title = "电台详情";
            });
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    if (this.form.radioStationId != null) {
                        updateStation(this.form).then(response => {
                            this.$modal.msgSuccess("修改成功");
                            this.open = false;
                            this.getList();
                        });
                    } else {
                        addStation(this.form).then(response => {
                            this.$modal.msgSuccess("新增成功");
                            this.open = false;
                            this.getList();
                        });
                    }
                }
            });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const radioStationIds = row.radioStationId || this.ids;
            this.$modal.confirm('是否确认删除电台编号为"' + radioStationIds + '"的数据项？').then(function () {
                return delStation(radioStationIds);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => { });
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download('business/station/export', {
                ...this.queryParams
            }, `station_${new Date().getTime()}.xlsx`)
        },
        getLocatedAddress(index) {
            const entries = this.dict.type.located_address;
            for (let i = 0; i < entries.length; i++) {
                if (entries[i].value == index) {
                    return entries[i].label
                }
            }
            return ""
        },
        getRadioStationType(index) {
            const entries = this.dict.type.radio_station_type;
            for (let i = 0; i < entries.length; i++) {
                if (entries[i].value == index) {
                    return entries[i].label
                }
            }
            return ""
        },

        changeType(index) {
            this.form.radioStationName = this.getRadioStationType(index) + this.form.radioStationId
        },
        changeLocatedAddress(index) {
            this.form.antennaId = null
            getAntennaListAll(index).then(response => {
                this.antennaListAll = response.rows;
            });

        },
    }
};
</script>
  